package com.blb.day06.config;

import org.redisson.Redisson;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.redisson.config.ClusterServersConfig;
import org.redisson.config.Config;
import org.redisson.config.SingleServerConfig;
import org.redisson.config.TransportMode;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;

@Configuration
public class RedissonConfig {

    @Bean
    public RBloomFilter<String> bloomFilter(){
        Config config = new Config();
        config.setTransportMode(TransportMode.NIO);
//        //单机版配置
//        SingleServerConfig singleServerConfig = config.useSingleServer();
//        //可以用"rediss://"来启用SSL连接
//        singleServerConfig.setAddress("redis://127.0.0.1:6379");
        //集群配置
        ClusterServersConfig clusterServersConfig = config.useClusterServers();
        clusterServersConfig.setNodeAddresses(Arrays.asList("redis://192.168.223.177:7001","redis://192.168.223.177:7002","redis://192.168.223.177:7003",
                "redis://192.168.223.177:7004","redis://192.168.223.177:7005","redis://192.168.223.177:7006"));
        RedissonClient redisson = Redisson.create(config);
        //创建布隆过滤器
        RBloomFilter<String> bloomFilter = redisson.getBloomFilter("student-filter");
        //初始化 参数1 向量长度 参数2 误识别率
        bloomFilter.tryInit(10000000L,0.03);
        return bloomFilter;
    }
}
